package com.heima.controller;


import com.heima.pojo.dto.PartnerDto;
import com.heima.pojo.dto.PartnerQuery;
import com.heima.pojo.vo.PartnerVo;
import com.heima.pojo.vo.PageVo;
import com.heima.service.IPartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author 存折
 * @since 2024-10-17
 */
@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {

    @Autowired
    private IPartnerService service;

    @PostMapping
    public Boolean add(@RequestBody PartnerDto partnerDto) {
        partnerDto.setCreateTime(LocalDateTime.now());
        partnerDto.setUpdateTime(LocalDateTime.now());
        service.save(partnerDto);
        return true;
    }

    @GetMapping("/search")
    public PageVo<PartnerVo> query(PartnerQuery partnerQuery) {
        return service.query(partnerQuery);
    }

    @GetMapping("/{id}")
    public PartnerDto findById(@PathVariable Integer id) {
        return service.getById(id);
    }

    @PutMapping("/{id}")
    public Boolean update(@PathVariable Integer id, @RequestBody PartnerDto partnerDto) {
        partnerDto.setId(id);
        service.updateById(partnerDto);
        return true;
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id){
        service.removeById(id);
        return true;
    }

}
